<?php

class App_Auth_Storage_Session implements Zend_Auth_Storage_Interface
{
    protected $_session;

    public function __construct($session)
    {
        $this->_session  = $session;
    }

    /**
     * Defined by Zend_Auth_Storage_Interface
     *
     * @return boolean
     */
    public function isEmpty()
    {
        return !isset($this->_session->{'user_id'});
    }

    /**
     * Defined by Zend_Auth_Storage_Interface
     *
     * @return mixed
     */
    public function read()
    {
        return array(
                'user_id'=>$this->_session->{'user_id'},
                'user_name'=>$this->_session->{'user_name'},
                'user_first_name'=>$this->_session->{'user_first_name'},
        		'user_last_name'=>$this->_session->{'user_last_name'},
        		'user_role'=>$this->_session->{'user_role'},
    			'last_login_at'=>$this->_session->{'last_login_at'}        
        );
    }

    /**
     * Defined by Zend_Auth_Storage_Interface
     *
     * @param  mixed $contents
     * @return void
     */
    public function write($contents)
    {
        //print_r($contents);
        
        $this->_session->{'user_id'} = $contents['user_id'];
        $this->_session->{'user_name'} = $contents['user_name'];
        $this->_session->{'user_first_name'} = $contents['user_first_name'];
        $this->_session->{'user_last_name'} = $contents['user_last_name'];
        $this->_session->{'user_role'} = $contents['user_role'];
        $this->_session->{'last_login_at'} = $contents['last_login_at'];          
    }

    /**
     * Defined by Zend_Auth_Storage_Interface
     *
     * @return void
     */
    public function clear()
    {
        unset($this->_session->{'user_id'});
        unset($this->_session->{'user_name'});
        unset($this->_session->{'user_first_name'});
        unset($this->_session->{'user_last_name'});
        unset($this->_session->{'user_role'});
        unset($this->_session->{'last_login_at'});
    }

    public function getUserName()
    {
        return $this->_session->{'user_name'};
    }

    public function setUserName($username)
    {
        $this->_session->{'user_name'}=$username;
    }

    public function getFirstName()
    {
        return $this->_session->{'user_first_name'};
    }
    
    public function getLastName()
    {
        return $this->_session->{'user_last_name'};
    }
    
    public function getUserId()
    {
        return $this->_session->{'user_id'};
    }

    public function getUserRole()
    {
        return $this->_session->{'user_role'};
    }

    public function getLastLogin()
    {
        return $this->_session->{'last_login_at'};
    }
}
